package threadstart;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : ThreadDemo2
 * @Author : 54061
 * @Date: 2022/2/15 12:36
 */
public class ThreadDemo2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException{
        //创建FutureTask对象
        FutureTask<String> ft = new FutureTask<>(new Callable<String>(){

            @Override
            public String call() throws Exception {
                //编写线程任务
                for (int i= 1; i <=100;i++){
                    System.out.println("屌丝给女神第" + i+ "次表白");
                }
                return "女神说滚";
            }
        });
        //创建线程对象,任务分配给线程
        Thread thread = new Thread(ft);
        //启动线程
        thread.start();

        for (int i = 0; i <100;i++){
            System.out.println("Hello"+i);
        }
        //获取线程结束
        String result = ft.get();
        System.out.println(result);
    }
}
